﻿#pragma execution_character_set("utf-8")

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
#include <QListWidget>
#include <QTreeWidget>
#include <QTabWidget>
#include <QIcon>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QWidget>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("SimpleEarth");
    this->setWindowIcon(QIcon(":/icons/planet-earth.png")) ;

    //this->setCentralWidget(ui->openGLWidget);
    createDockWindows();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::createDockWindows()
{
    //搜索Widget
    QWidget* searchWidget = new QWidget(this) ;
    QVBoxLayout* vLayout = new QVBoxLayout(searchWidget);
    QHBoxLayout* hLayout = new QHBoxLayout(searchWidget);
    searchWidget->setLayout(vLayout);
    QLineEdit* lineEdit = new QLineEdit(searchWidget) ;
    QPushButton* searchButton = new QPushButton(searchWidget) ;
    searchButton->setText("搜索");
    hLayout->addWidget(lineEdit);
    hLayout->addWidget(searchButton);
    vLayout->addItem(hLayout) ;
    vLayout->addStretch(1);


    QDockWidget* dock1 = new QDockWidget("搜索",this);
    dock1->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    QTabWidget* tabs = new QTabWidget(dock1) ;
    tabs->addTab(searchWidget , "位置");
    tabs->addTab(new QWidget() , "路径");
    tabs->addTab(new QWidget() , "图片");
    dock1->setWidget(tabs) ;
    addDockWidget(Qt::LeftDockWidgetArea,dock1) ;

    QDockWidget* dock2 = new QDockWidget("轨迹",this) ;
    dock2->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    QTreeWidget* tree = new QTreeWidget(dock2) ;
    createTrackTreeItems(tree) ;
    dock2->setWidget(tree);
    addDockWidget(Qt::LeftDockWidgetArea, dock2) ;

    QDockWidget* dock3 = new QDockWidget("图层",this);
    dock3->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    QTreeWidget* treeLayers = new QTreeWidget(dock3) ;
    dock3->setWidget(treeLayers);
    addDockWidget(Qt::LeftDockWidgetArea, dock3) ;
    createLayerItems(treeLayers);


}

void MainWindow::createTrackTreeItems(QTreeWidget* tree)
{
    tree->setHeaderHidden(true);

    QIcon dir_icon = QApplication::style()->standardIcon(QStyle::SP_DirIcon);
    QIcon file_icon = QApplication::style()->standardIcon(QStyle::SP_FileIcon);

    QTreeWidgetItem* my = new QTreeWidgetItem(tree) ;
    my->setText(0,"我的地点") ;
    my->setIcon(0,dir_icon);

    QTreeWidgetItem* tour = new QTreeWidgetItem(my) ;
    tour->setText(0,"观光游览");
    tour->setIcon(0,dir_icon);
    QTreeWidgetItem* t1 = new QTreeWidgetItem(tour) ;
    t1->setText(0,"比萨斜塔");
    t1->setIcon(0,file_icon);
    QTreeWidgetItem* t2 = new QTreeWidgetItem(tour) ;
    t2->setText(0,"杭州");//
    t2->setIcon(0,file_icon);
    QTreeWidgetItem* t3 = new QTreeWidgetItem(tour) ;
    t3->setText(0,"大理");
    t3->setIcon(0,file_icon);
    QTreeWidgetItem* t4 = new QTreeWidgetItem(tour) ;
    t4->setText(0,"大连");
    t4->setIcon(0,file_icon);


    QTreeWidgetItem* temp = new QTreeWidgetItem(my) ;
    temp->setText(0,"临时位置");
    temp->setIcon(0,dir_icon);

}

void MainWindow::createLayerItems(QTreeWidget* tree)
{
    tree->setHeaderHidden(true);

    QIcon dir_icon = QApplication::style()->standardIcon(QStyle::SP_DirIcon);
    QIcon file_icon = QApplication::style()->standardIcon(QStyle::SP_FileIcon);

    QTreeWidgetItem* all = new QTreeWidgetItem(tree);
    all->setText(0,"我的图层");
    all->setIcon(0,dir_icon);
    all->setCheckState(0, Qt::CheckState::PartiallyChecked);

    QTreeWidgetItem* tnotify = new QTreeWidgetItem(all) ;
    tnotify->setText(0,"通告");
    tnotify->setIcon(0,file_icon);
    tnotify->setCheckState(0, Qt::CheckState::Unchecked) ;

    QTreeWidgetItem* tborder = new QTreeWidgetItem(all) ;
    tborder->setText(0, "边界与地名");
    tborder->setIcon(0,dir_icon);
    tborder->setCheckState(0, Qt::CheckState::Checked) ;

    QTreeWidgetItem* t21 = new QTreeWidgetItem(tborder) ;
    t21->setText(0, "边界");
    t21->setIcon(0,file_icon);
    t21->setCheckState(0, Qt::CheckState::Checked) ;

    QTreeWidgetItem* t22 = new QTreeWidgetItem(tborder) ;
    t22->setText(0, "地名");
    t22->setIcon(0,file_icon);
    t22->setCheckState(0, Qt::CheckState::Checked) ;


    QTreeWidgetItem* tlocation = new QTreeWidgetItem(all) ;
    tlocation->setText(0,"地点");
    tlocation->setIcon(0,file_icon);
    tlocation->setCheckState(0, Qt::CheckState::Checked) ;

    QTreeWidgetItem* tpic = new QTreeWidgetItem(all) ;
    tpic->setText(0,"照片");
    tpic->setIcon(0,file_icon);
    tpic->setCheckState(0, Qt::CheckState::Unchecked) ;

    QTreeWidgetItem* troads = new QTreeWidgetItem(all) ;
    troads->setText(0,"道路");
    troads->setIcon(0,file_icon);
    troads->setCheckState(0, Qt::CheckState::Checked) ;

    QTreeWidgetItem* tbuildings = new QTreeWidgetItem(all) ;
    tbuildings->setText(0,"3D建筑");
    tbuildings->setIcon(0,file_icon);
    tbuildings->setCheckState(0, Qt::CheckState::Unchecked) ;

    QTreeWidgetItem* tweather = new QTreeWidgetItem(all) ;
    tweather->setText(0,"气象");
    tweather->setIcon(0,dir_icon);
    tweather->setCheckState(0, Qt::CheckState::Unchecked) ;
    QTreeWidgetItem* tcloud = new QTreeWidgetItem(tweather) ;
    tcloud->setText(0,"云层");
    tcloud->setIcon(0,file_icon);
    tcloud->setCheckState(0,Qt::CheckState::Unchecked);
    QTreeWidgetItem* twind = new QTreeWidgetItem(tweather) ;
    twind->setText(0,"风场");
    twind->setIcon(0,file_icon);
    twind->setCheckState(0,Qt::CheckState::Unchecked);

    QTreeWidgetItem* tterrain = new QTreeWidgetItem(all) ;
    tterrain->setText(0,"地形");
    tterrain->setIcon(0,file_icon);
    tterrain->setCheckState(0, Qt::CheckState::Checked) ;


}
